<template>
	<div class="page1">
		<!--面包屑-->
		<div class="breadcrumb">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>系统管理</el-breadcrumb-item>
				<el-breadcrumb-item>系统用户管理</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<!--主体内容-->
		<div class="content">
			<h2 class="title">
				<div class="title_icon">						
				</div>
				添加/修改功能
			</h2>
			<!--搜索条件区域-->
			<div class="searchWrapper">
				
						<el-form label-position="right" label-width="100px" :model="formInline" style="width: 440px;" :rules="rules" :ref="'form'">
							<el-form-item label="功能名称" prop="resourceName">
								<el-input v-model.trim="formInline.resourceName"></el-input>
							</el-form-item>
							<el-form-item label="功能图标">
								<el-input v-model.trim="formInline.icon"></el-input>
							</el-form-item>
							<el-form-item label="显示顺序">
								<el-input v-model.trim="formInline.orderby"></el-input>
							</el-form-item>
							<el-form-item label="父功能名称">
								<el-select v-model.trim="formInline.parentId" filterable placeholder="">
									<el-option label="请选择" value=""></el-option>
									<el-option v-for="item in resourceList" :label="item.resourceName" :value="item.resourceId"></el-option>									
								</el-select>
							</el-form-item>
							<el-form-item label="功能类型">
								<el-select v-model.trim="formInline.resourceType" filterable placeholder="">
									<el-option label="菜单" value="menu"></el-option>
									<el-option label="功能" value="function"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="地址">
								<el-input v-model.trim="formInline.url"></el-input>
							</el-form-item>
							<el-form-item label="备注">
								<el-input v-model.trim="formInline.remark"></el-input>
							</el-form-item>
						</el-form>
				<div style="text-align: center; margin-top: 20px; ">
					<el-button type="primary" @click="submitData" style="width: 88px;">提交</el-button>
					<el-button type="" @click="$router.replace({path: '/funcManage'})" style="width: 88px;">取消</el-button>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import {
		getData
	} from '../../common/js/public.js'
	export default {
		name: 'hello',
		data () {
			return {	
				isEdit: false,
				resourceList: [],
				formInline: {
					parentId: '',
					resourceName: '',
					icon: '',
					orderby: '',
					resourceType: 'menu',
					url: '',
					remark: ''
				},
				rules: {
					resourceName: [{
						required: true,
						message: '请输入功能名称',
						trigger: 'blur'
					}]
				}
			}
		},
		methods: {	
			queryDetail () {				
				let opt = {
					url: '/gplus/resource/queryList',
					data: {
						"resourceId": this.$route.query.resourceId
					},
					success: (res) => {
						for (let i in this.formInline) {							
							this.formInline[i] = res.data.ResourceVO[0][i].toString();
						}
						console.log(this.formInline)
					},
					fail: (res) => {
						this.$alert(res.msg, '提示', {
							confirmButtonText: '确定'
						});
					}
				};
				getData(opt);
			},
			getResource () {
				let opt = {
					url: '/gplus/resource/queryList',
					data: {
						"applicationPlatform": "0"
					},
					success: (res) => {
						this.resourceList = res.data.ResourceVO;
					},
					fail: (res) => {
						this.$alert(res.msg, '提示', {
							confirmButtonText: '确定'
						});
					}
				};
				getData(opt);
			},
			addList () {
				let opt = {
					url: !this.isEdit ? '/gplus/resource/add' : '/gplus/resource/update',
					data: this.formInline,
					success: (res) => {
						this.$alert(res.msg, '提示', {
							confirmButtonText: '确定'
						}).then(() => {
							this.$router.replace({
								path: 'funcManage'
							});
						});
					},
					fail: (res) => {
						this.$alert(res.msg, '提示', {
							confirmButtonText: '确定'
						});
					}
				};
				getData(opt);
			},
			submitData () {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.addList();
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}			
		},
		components: {},
		mounted () {
			this.getResource();
			if (this.$route.query.resourceId) {		
				this.isEdit = true;
				this.queryDetail();
			}
		},
		computed: {
		}
	}
</script>	
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus" rel="stylesheet/stylus">
.breadcrumb 
	height: 30px;
	overflow: hidden;	
.content	
	background: #FFFFFF;
	overflow: hidden;
	border: 1px solid #C0CCDA;
	border-radius: 4px;
	padding: 20px;
</style>
